/*
 * CourseViewInterFrm.java
 *
 * Created on __DATE__, __TIME__
 */

package com.jakey.view;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.Vector;

import javax.swing.table.DefaultTableModel;

import com.jakey.dao.CourseDao;
import com.jakey.model.Course;
import com.jakey.util.DbUtil;

import Message.Message;
import client.TheClient;
import gui.MyTable;
import user.User;

import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import java.awt.Dimension;
import java.awt.Color;

/**
 *
 * @author  __USER__
 */
public class CourseViewInterFrm extends javax.swing.JInternalFrame {

	CourseDao courseDao = new CourseDao();

	/** Creates new form CourseViewInterFrm */
	public CourseViewInterFrm() {
		//getContentPane().setBackground(new Color(64, 116, 52));
		getContentPane().setBackground(new Color(240,240,240));
		setPreferredSize(new Dimension(700, 433));
		initComponents();
		this.setLocation(200, 50);
		this.fillTable(new Course());
		MyTable.colorizeTabel(courseTable);
	}

	public CourseViewInterFrm(User user) {
		//getContentPane().setBackground(new Color(64, 116, 52));
		getContentPane().setBackground(new Color(240,240,240));
		setPreferredSize(new Dimension(700, 433));
		initComponents();
		this.setLocation(200, 50);
		this.fillTable(new Course());
		MyTable.colorizeTabel(courseTable);
	}

	private void fillTable(Course course) {
		DefaultTableModel dtm = (DefaultTableModel) courseTable.getModel();
		dtm.setRowCount(0);
		String tp="SHOW_READERS";
		Course course1 = new Course();
		Message message=new Message(tp,course1);
		message.setCheckCode(6);

		client.TheClient client=new TheClient();
		Message received;
		try {
			received = client.sendAndReceive(message);
			Vector<Course> TbB = new Vector<Course>();
			TbB = received.getCsvecVector();
			for(int i=0;i<TbB.size();i++) {
				Course temp = new Course();
				Vector v = new Vector();
				temp = TbB.get(i);
				v.add(temp.getCourseId());
				v.add(temp.getCourseName());
				v.add(temp.getCourseTime());
				v.add(temp.getCourseTeacher());
				v.add(temp.getCapacity());
				v.add(temp.getNumSelected());
				dtm.addRow(v);

			}
		}catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
			
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
//GEN-BEGIN:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();
courseTable = new MyTable();

setClosable(true);
setIconifiable(true);
setTitle("\u8bfe\u7a0b\u67e5\u770b");

courseTable.setModel(new javax.swing.table.DefaultTableModel(
	new Object [][] {
		
	},
	new String [] {
		"课程编号", "课程名称", "上课时间", "任课老师", "课程容量", "已选人数"
	}
) {
	boolean[] canEdit = new boolean [] {
		false, false, false, false, false, false
	};

	public boolean isCellEditable(int rowIndex, int columnIndex) {
		return canEdit [columnIndex];
	}
});
jScrollPane1.setViewportView(courseTable);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
layout.setHorizontalGroup(
	layout.createParallelGroup(Alignment.LEADING)
		.addGroup(layout.createSequentialGroup()
			.addContainerGap()
			.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 668, Short.MAX_VALUE)
			.addContainerGap())
);
layout.setVerticalGroup(
	layout.createParallelGroup(Alignment.LEADING)
		.addGroup(layout.createSequentialGroup()
			.addContainerGap()
			.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 263, Short.MAX_VALUE)
			.addContainerGap())
);
getContentPane().setLayout(layout);

pack();
}// </editor-fold>
//GEN-END:initComponents

//GEN-BEGIN:variables
// Variables declaration - do not modify
private javax.swing.JTable courseTable;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables

}